home *** CD-ROM | disk | FTP | other *** search
- /*
- WASTE Demo Project:
- Dialog Utilities
-
- Copyright © 1993-1997 Marco Piovanelli
- All Rights Reserved
-
- C port by John C. Daub
- */
-
- #ifndef __DIALOGS__
- #include <Dialogs.h>
- #endif
-
- #ifndef __WEDEMOAPP__
- #include "WEDemoIntf.h"
- #endif
-
- static pascal Boolean MyStandardDialogFilter( DialogRef dialog, EventRecord *event, SInt16 *item )
- {
- GrafPtr savePort;
- ModalFilterUPP stdFilter = nil;
- Boolean retval = false;
- OSErr err;
-
- // set up the port
- GetPort( &savePort );
- SetGrafPortOfDialog( dialog );
-
- // intercept window events directed to windows behind the dialog
- if ( ( event->what == updateEvt ) || ( event->what == activateEvt ) )
- {
- if ( ((WindowRef) event->message) != GetDialogWindow( dialog ) )
- {
- DoWindowEvent( event );
- }
- }
-
- // is the default item a pushbutton?
- if ( GetDialogItemType( dialog, GetDialogDefaultItem( dialog ) ) == kButtonDialogItem )
- {
- // yes, so tell the Dialog Manager to care about its outline
- SetDialogDefaultItem( dialog, GetDialogDefaultItem( dialog ));
- }
-
- // this is something not in the original WASTE Demo App, but in the work that I've done
- // on my own projects, I've found it useful and helpful.
-
- // let's also make sure the cancel button can be handled...now, the cancel button
- // should be dialog item #2. So, we get dialog item #2, check if it's a button.
- // if it fills these 2 criteria, it's cancel. Even if the default item and the
- // cancel item are the same, still let them both be set this way so whatever keyboard
- // keys sthe user presses will be handled properly
-
- // pass the number "2" to GetDialogItemType...don't check for the cancel item (cause tho
- // cancel is defined as 2, we're not looking for cancel, we're looking for dialog item #2
- // this is just more readable code.
-
- // remember, this assumes that your cancel item will be item #2 (or at least the item
- // that you want to use for cancelling is #2), and that there are at least 2 items in
- // the dialog to begin with!
-
- if ( GetDialogItemType( dialog, kStdCancelItemIndex ) == kButtonDialogItem )
- {
- SetDialogCancelItem( dialog, kStdCancelItemIndex );
- }
-
- // call the standard Dialog Manager filter procedure
-
- if ( ( ( err = GetStdFilterProc( &stdFilter ) ) == noErr ) && ( stdFilter != nil ) )
- {
- retval = CallModalFilterProc( stdFilter, dialog, event, item );
- }
-
- // restore the port
- SetPort( savePort );
-
- return retval;
- }
-
- ModalFilterUPP GetMyStandardDialogFilter( void )
- {
- #ifdef __cplusplus
- static ModalFilterUPP sFilterUPP = NewModalFilterProc( MyStandardDialogFilter );
- #else
- static ModalFilterUPP sFilterUPP = nil;
-
- if ( sFilterUPP == nil )
- {
- sFilterUPP = NewModalFilterProc( MyStandardDialogFilter );
- }
- #endif
-
- return sFilterUPP;
- }
-
- SInt16 GetDialogItemType( DialogRef dialog, SInt16 item )
- {
- SInt16 itemType;
- Handle itemHandle;
- Rect itemRect;
-
- GetDialogItem( dialog, item, &itemType, &itemHandle, &itemRect );
-
- return itemType;
- }
-
- Handle GetDialogItemHandle( DialogRef dialog, SInt16 item )
- {
- SInt16 itemType;
- Handle itemHandle;
- Rect itemRect;
-
- GetDialogItem( dialog, item, &itemType, &itemHandle, &itemRect );
-
- return itemHandle;
- }
-
- void GetDialogItemRect( DialogRef dialog, SInt16 item, Rect *itemRect )
- {
- SInt16 itemType;
- Handle itemHandle;
-
- GetDialogItem( dialog, item, &itemType, &itemHandle, itemRect );
- }
-
- void SetDialogItemProc( DialogRef dialog, SInt16 item, UserItemUPP proc )
- {
- SInt16 itemType;
- Handle itemHandle;
- Rect itemRect;
-
- GetDialogItem( dialog, item, &itemType, &itemHandle, &itemRect );
-
- if ( ( itemType & 0x007F) == userItem )
- {
- SetDialogItem( dialog, item, itemType, (Handle) proc, &itemRect );
- }
- }
-
- void FlashButton( DialogRef dialog, SInt16 item )
- {
- ControlRef button;
- SInt32 finalTicks;
-
- button = (ControlRef) GetDialogItemHandle( dialog, item );
- HiliteControl( button, kControlButtonPart );
- Delay( 8, &finalTicks );
- HiliteControl( button, kControlNoPart );
- }
-